package com.lost.octopus.es.processor.entity;

import lombok.Data;
import org.springframework.beans.BeanUtils;

@Data
public class ShareListRequest<I> {

    private PageIn page;
    private I data;
    private boolean ignoreCache = false;

    public <I2> ShareListRequest<I2> to(Class<I2> cls) throws InstantiationException, IllegalAccessException {
        if (this.getData() == null
            || this.getData().getClass().isAssignableFrom(cls)) {
            return (ShareListRequest) this;
        }
        ShareListRequest shareListRequest = new ShareListRequest();
        shareListRequest.setPage(PageIn.builder()
            .currentPage(this.getPage().getCurrentPage())
            .linesPerPage(this.getPage().getLinesPerPage())
            .orderBys(this.getPage().getOrderBys())
            .build()
        );
        I2 i2 = cls.newInstance();
        BeanUtils.copyProperties(this.getData(), i2);
        shareListRequest.setData(i2);
        return shareListRequest;
    }


}
